home *** CD-ROM | disk | FTP | other *** search
- Enitity Access Fun with AutoLISP Version 2.5
-
- ZOOOM! by Ted Schaefer 10/7/86
-
-
- Let's have some fun with AutoLISP. We'll create an AutoLISP
- routine, ZOOOM, which borders on animation. ZOOOM will take the
- last block inserted in a drawing, scale it up a little and repeat
- the process 20 times. The only difference between this process
- and true animation is the speed of the computer.
-
- Because this involves enitity access, the ZOOOM routine requires
- AutoCAD Version 2.5. What we'll do is take the last entity, pull
- out the scale factors for X and Y (there is a Z). Then they will
- be rescaled by multiplying them by 1.25. The new scale factors
- then will be substituted for the old ones. Finally, the entity
- description will be used to update the inserted block.
-
- Here's the ZOOOM routine:
-
- 1. (DEFUN C:ZOOOM ()
- 2.
- 3. (setq e (entget (entlast)))
- 4. (setq oldx (assoc 41 e))
- 5. (setq oldy (assoc 42 e))
- 6. (setq scalex (* (cdr oldx) 1.25))
- 7. (setq scaley (* (cdr oldy) 1.25))
- 8.
- 9. (REPEAT 20
- 10.
- 11. (setq new41 (cons 41 scalex))
- 12. (setq new42 (cons 42 scaley))
- 13.
- 14. (setq scalex (* scalex 1.25))
- 15. (setq scaley (* scaley 1.25))
- 16.
- 17. (setq e (subst new41 oldx e))
- 18. (entmod (setq e (subst new42 oldy e)))
- 19.(setq oldx new41)
- 20.(setq oldy new42)
- 21.)
- 22. )
-
- (The line numbers are for reference only, not to be typed in.)
-
- What do the lines mean? Line 1 says that we're defining a
- function. With the "C:" we're saying we want the function to
- behave just like another AutoCAD command, such as LINE or BREAK.
-
- The command will be executed from AutoCAD's command prompt by
- typing in the word ZOOOM. Note that we had to use a name
- slightly different than a normal AutoCAD command. At the end of
- the line are two parentheses, where local variables can be
- defined. We won't bother.
-
- Line 2 finds the name of the last entity with the "entlast"
- command. Then, using "entget", we "get" all the properties of
- the entity whose name was specified with "entlast". We then
- store those properties in a variable "e" using the "setq"
- command.
-
- After running ZOOOM, you can type !e, and examine the contents
- of this variable. What you'll see is about three line of text
- grouped with parentheses. Within each group is a code number and
- a value. The number and the value form a "list". The codes are
- spelled out by the AutoCAD DXF format. The code numbers for the
- X and Y scale factors are 41 and 42. Lines 4 and 5 use the
- "assoc" command to break out the values and assign them to the
- variables "oldx" and "oldy".
-
- Lines 6 and 7 then multiply the scale factors and store them in
- variables "scalex" and "scaley". You can change the 1.25
- multiplier for different effects.
-
- We now have the information needed to go into the repeating loop
- at line 9, which is set for 20 repetitions. Lines 11 and 12
- construct the new lists containing the code number and increased
- scale factors using the "cons" command. The lists are then
- stored under variables "new41" and "new42".
-
- In lines 14 and 15, the scale factors are increased and stored
- under their old variable names.
-
- Next, we must substitute our new lists with increased scale
- factors into the complete description of the symbol/block
- (or entity). This is done on lines 17 and 18 using the "subst"
- command. Line 18 goes further. Using the "entmod" command, we
- modify the entity whose name and description are stored under the
- variable "e" which we have changed. This produces the visible
- change on the screen.
-
- Now the new scale factors have been used; therefore, they're old!
- Lines 19 and 20 assign new to old. This is the end of the loop.
- The program then returns to line 9 and repeats the steps
- between 9 and 21. Line 21 closes off the end of the REPEAT loop
- and 22 closes the DEFUN.
-
- Well, that was fun, but what kind of serious work can be done
- with entity access? How about a command call TEXTFIT that
- allows you to move text and squeeze it or expand it without
- changing styles? How about an EXPORT routine that takes text
- off your drawing and puts it in a word processing file? How
- about a command called FIND that searches your drawing and counts
- the number of occurrences of anything? How about a command
- called PLENGTH that measures the length of a polyline without
- using the LIST command?
-
- What a about a command that searches your drawing for text of one
- size and converts it to another? Or changes one style to
- another? Your imagination is the only limit to the
- possibilities. ZOOOOOOOM on!
-
- End